﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

using SimpleText.Framework;

public partial class LegacyConvertProjectPage : SimpleTextPage
{


  protected void Page_Load(object sender, EventArgs e)
  {
		InitPage();
	}

	protected void ConvertProjectBtn_Clicked(object sender, EventArgs e)
	{
		string projectPathAndFileName = Request.QueryString["projectfile"];
		XmlDocument xmlDoc = new XmlDocument();
		xmlDoc.Load(projectPathAndFileName);
		
		XmlNode rootNode = xmlDoc.SelectSingleNode("languageversioning");
		//create a new textDefinitions node and move all existing textDefinition nodes to is
		XmlNodeList textDefinitionNodes = rootNode.SelectNodes("//textDefinition");
		XmlNode newTextdefNode = xmlDoc.CreateNode(XmlNodeType.Element, "textDefinitions", null);
		foreach (XmlNode textdefNode in rootNode.SelectNodes("//textDefinition"))
		{
			newTextdefNode.AppendChild(textdefNode);
		}
		rootNode.AppendChild(newTextdefNode);
		//remove the old textDefinitionGroups node
		XmlNode groupsNode = xmlDoc.SelectSingleNode("//textDefinitionGroups");
		rootNode.RemoveChild(groupsNode);

		//save doc and load project
		xmlDoc.Save(projectPathAndFileName);

		SetCurrentModel(projectPathAndFileName);

		Response.Redirect("~");
	}
}
